package com.itheima.pattern.t15_reponsibility.demo1;

/**
 * 抽象处理者类
 */
public abstract class Handler {

    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;

    // 该领导处理的请假天数区间
    private int numStrat;
    private int numEnd;

    // 声明后继者(上级领导)
    private Handler nextHandler;

    public Handler(int numStrat) {
        this.numStrat = numStrat;
    }

    public Handler(int numStrat, int numEnd) {
        this.numStrat = numStrat;
        this.numEnd = numEnd;
    }

    public Handler getNextHandler() {
        return nextHandler;
    }

    // 设置上级领导对象
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    // 各级领导处理请假条的方法
    protected abstract void handleLeave(LeaveRequest leave);

    // 提交请假条
    public final void submit(LeaveRequest leave) {
        if (leave.getNum() > this.numStrat) {
            // 该领导先进行审批
            this.handleLeave(leave);
            if (leave.getNum() > this.numEnd) {
                if (this.nextHandler != null) {
                    // 提交给上级领导进行审批
                    this.nextHandler.submit(leave);
                } else {
                    System.out.println("当前没有人审核！");
                    return;
                }
            } else {
                System.out.println("流程结束！");
            }
        }
    }
}
